package com.br.gui.aicoach;
import java.util.ArrayList;

import com.br.aicoach.R;
import com.br.aicoach.R.id;
import com.br.aicoach.R.layout;
import com.br.aicoach.R.menu;
import com.br.bd.aicoach.Banco;
import com.br.dominio.aicoach.ListaTimesAdapter;
import com.br.dominio.aicoach.Time;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class TelaListaTimes extends Activity {

	ArrayList<Time> listaTimes;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_tela_lista_times);
		Banco banco=new Banco(this);
		listaTimes=banco.retornarListaTimes();
		Time.setListaTimes(listaTimes);
		//faz o listView ter os nomes de times
		 ArrayAdapter ad = new ListaTimesAdapter(this, R.layout.item, listaTimes);
	     ListView lv = (ListView) findViewById(R.id.lvTimes);
	     lv.setAdapter(ad);
	     
	     
	     lv.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
						long arg3) {
					Intent intent = new Intent(TelaListaTimes.this,TelaTimes.class);
					int position=arg2;
					intent.putExtra("position", position);
					startActivity(intent);
				}
				
			});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.tela_lista_times, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * A placeholder fragment containing a simple view.
	 */

}
